package io.ai.arch.java.ai;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/ai/client")
public class ChatClientApi {

    private final ChatModel chatModel;

    private final ChatClient chatClient;

    public ChatClientApi(ChatModel cm) {
        chatModel = cm;
        chatClient = ChatClient.create(chatModel);
    }

    @GetMapping("/prompt")
    String prompt(@RequestParam(value = "message", defaultValue = "讲个笑话") String userInput) {
        return this.chatClient.prompt().call().content();
    }

    @GetMapping("/chineseClientString")
    String chineseClientString(@RequestParam(value = "message", defaultValue = "讲个笑话") String userInput1) {
        return this.chatClient.prompt(userInput1).call().content();
    }


    @GetMapping("/clientString")
    String clientString(@RequestParam(value = "message", defaultValue = "讲个笑话") String userInput2) {
        return this.chatClient.prompt(userInput2).call().content();
    }

    @GetMapping("/clientPrompt")
    String clientPrompt(@RequestParam(value = "message", defaultValue = "讲个笑话") String userInput3) {
        Prompt prompt = new Prompt(new UserMessage(userInput3));
        return this.chatClient.prompt(prompt).call().content();
    }
}
